package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: xiang
 * @Date: 2019/8/18 11:57
 * @Description:
 */

@RestController
@RequestMapping("spec")
public class SpecController {
    @Autowired
    private SpecService specService;

    /**
     * 根据商品分类查询商品规格参数组id
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> specGroup(@RequestParam("id") Long id){

        return ResponseEntity.ok(specService.specGroup(id));

    }
    @GetMapping("params")
    public ResponseEntity<List<SpecParamDTO>> querySpecParam(@RequestParam(value = "gid", required=false) Long gid , @RequestParam(value = "cid" ,required = false) Long cid,
                                                             @RequestParam(value = "searching", required = false) Boolean searching){
          return ResponseEntity.ok(specService.querySpceParam(gid,cid,searching));


    }

    /**
     * 通过分类id直接查询分组，并且根据分组查到参数，就是分组包含参数
     * @param cid
     * @return
     */
    @GetMapping("of/category")
    public ResponseEntity<List<SpecGroupDTO>> querySpecsBycid(@RequestParam("cid") Long cid){
        return ResponseEntity.ok(specService.querySpecsByCid(cid));

    }


}